<style type="text/css" scoped="scoped">
    .roleadd .parentname {
        cursor: pointer;
    }

    .roleadd textarea {
        min-width: 300px;
        min-height: 100px;
    }

    .roleaddtree {
        display: none;
    }

    .roleaddtree .rolename {
        cursor: pointer;
    }
</style>
<@com.toolbar />
<div class="roleadd">
    <div class="group">
        <div class="label">角色名称：</div>
        <div class="value"><input type="text" name="name" regx="${check.name}"/></div>
    </div>
    <div class="group">
        <div class="label">上级角色：</div>
        <div class="value">
            <input type="hidden" name="parentId" value="${parentId}"/>
            <span class="parentname" onClick="$('.roleaddtree').dialog('open')" title="点击选择父角色"></span>
        </div>
    </div>
    <div class="group">
        <div class="label">备　　注：</div>
        <div class="value"><textarea name="notes" nullable></textarea></div>
    </div>
    <div class="roleaddtree">
    <#list roles as m>
        <div id="${m._id}" pid="${m.parentId}">
            <span class="rolename" title="${m.notes!""}"><span class="icon-user2"></span>
            <span class="name"
                  onClick="choseParent('${m._id}');$('.roleaddtree').dialog('close')">${m.name}</span></span>
        </div>
    </#list>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function (e) {
        var roleaddtree = $('.roleadd .roleaddtree').jTree();
        roleaddtree.showAll();
        $('.parentname').button();
        choseParent('${parentId}');
        dialog('.roleaddtree', {
            autoOpen: false,
            modal: true,
            title: "选择上级角色"
        });
        LC.initToolbarAdd();
    });
    function choseParent(pid) {
        console.error('pid=' + pid)
        if (pid == '') {
            pid = '0';
        }
        var parent = $('#' + pid);
        if (parent.length == 0) {
            parent = $('[pid=0]');
        }
        $('.parentname').children().text(parent.find('.name:first').text());
        $('input[name=parentId]').val(parent.attr('id'));
    }
</script>